package leetcodecompetition.S117;

import java.util.PriorityQueue;

/**
 * @Author: Siantar
 * @Date: 2023-11-11-23:10
 * @Description: 1.0
 */
public class T100043 {
    public long maxSpending(int[][] values) {
        long res = 0, t = 1;
        PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> a[2] - b[2]);
        int m = values.length, n = values[0].length;
        for (int i = 0; i < m; i++) {
            pq.offer(new int[]{i, n - 1, values[i][n - 1]});
        }
        while (!pq.isEmpty()) {
            int[] e = pq.poll();
            int ei = e[0], ej = e[1], ev = e[2];
            res += t * ev;
            if (ej > 0) {
                pq.offer(new int[]{ei, ej - 1, values[ei][ej]});
            }
            System.out.println(ev);
            t++;
        }
        return res;
    }


}
